<?php
/**
 * <https://y.st./>
 * Copyright © 2019 Alex Yst <mailto:copyright@y.st>
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <https://www.gnu.org./licenses/>.
**/

$xhtml = array(
	'<{title}>' => 'Alex Yst',
	'<{subtitle}>' => 'Bachelor degree progress',
	'<{copyright year}>' => '2019',
	'<{body}>' => "<pre>yst@localhost:~\$ degree_progress.sh\n",
);

$current_courses = array(
	'CS4405' => true,
	'CS4406' => true,
);
$course_completion_count = 0;

foreach($saved_state['courses'] as $key => $value):
	$temp = substr($key, 0, -4).' '.substr($key, -4).": $value";
	if(strlen($temp) >= 68):
		$break = 68;
		while($temp[$break] != ' '):
			--$break;
		endwhile;
		$xhtml['<{body}>'] .= substr($temp, 0, $break)."\n";
		$temp = '   '.substr($temp, $break);
	endif;
	if(isset($current_courses[$key])):
		$status = 'In-progress';
	elseif(isset($coursework[$key]) and empty($coursework[$key]['assignments']['Unit_7_essay'])):
		$status = 'Complete';
		++$course_completion_count;
	else:
		$status = 'Planned';
	endif;
	$xhtml['<{body}>'] .= str_pad($temp.' ', 68, '.')." $status\n";
endforeach;

$xhtml['<{body}>'] .= "\nCourses completed: $course_completion_count/".count($saved_state['courses']).' ('.floor(100*$course_completion_count/count($saved_state['courses']))."%)\nyst@localhost:~\$";
$xhtml['<{body}>'] .= '</pre>';
